package com.shop2cn.iapi.sellerpromotion.testcase;

import java.io.IOException;
import java.util.Map;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.shop2cn.iapi.sellerpromotion.parameter.CreatePromotionBean;
import com.shop2cn.iapi.sellerpromotion.parameter.PromotionDeleteBean;
import com.shop2cn.iapi.sellerpromotion.service.PromotionDeleteCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.Shop2cnSellerPromotionCallService;
import com.ymttest.business.service.shenqi.GodmchManageCallService;
import com.ymttest.database.mongo.Shop2cnSellerPromotionInfoWapper;
import com.ymttest.utils.YMTDateUtil;
/**
*删除满减
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_PromotionDelete{
	private static PromotionDeleteBean promotiondeleteBean;
	private static PromotionDeleteCall promotiondeleteCall;
	private static Integer mchId;
	private static Shop2cnSellerPromotionInfoWapper Shop2cnSellerPromotionInfoWapper;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("删除满减");
		try {
			Shop2cnSellerPromotionInfoWapper=new Shop2cnSellerPromotionInfoWapper();
			mchId=GodmchManageCallService.CreateSellerMch();
		} catch (Exception e) {
		}
	}

	@Before
	public void caseUp() {
		promotiondeleteBean=new PromotionDeleteBean();
		promotiondeleteCall=new PromotionDeleteCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(promotiondeleteCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
		try {
			Shop2cnSellerPromotionCallService.EndAllEnablePromotion(mchId);
		} catch (IOException e) {
//			e.printStackTrace();
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_PromotionDelete_001() {
		Logger.start(true,"已结束删除满减成功");
		try {
			CreatePromotionBean createpromotionBean = Shop2cnSellerPromotionCallService.initCreatePromotionBean(mchId, 1);
			Integer promotionId = Shop2cnSellerPromotionCallService.CreatepromotionCall(createpromotionBean);
			Shop2cnSellerPromotionCallService.PromotionEnd(mchId, promotionId);
			promotiondeleteBean.setPromotionId(promotionId);
			promotiondeleteBean.setSellerId(mchId);
			promotiondeleteCall.setData(promotiondeleteBean);
			promotiondeleteCall.callService();			
			Logger.verifyEquals("200", promotiondeleteCall.getString("code"), "验证返回");
			Map m = Shop2cnSellerPromotionInfoWapper.getPromotionById(promotionId);
			Logger.debug(m);
			Logger.verifyEquals(true, m.get("isdel"), "验证isdel");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P3.class})
	@TestCase
	public void Tc_PromotionDelete_002() {
		Logger.start(true,"不输入sellerid失败");
		try {
			CreatePromotionBean createpromotionBean = Shop2cnSellerPromotionCallService.initCreatePromotionBean(mchId, 1);
			Integer promotionId = Shop2cnSellerPromotionCallService.CreatepromotionCall(createpromotionBean);
			Shop2cnSellerPromotionCallService.PromotionEnd(mchId, promotionId);
			promotiondeleteBean.setPromotionId(promotionId);
//			promotiondeleteBean.setSellerId(mchId);
			promotiondeleteCall.setData(promotiondeleteBean);
			promotiondeleteCall.callService();			
			Logger.verifyEquals("400", promotiondeleteCall.getString("code"), "验证返回");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P3.class})
	@TestCase
	public void Tc_PromotionDelete_003() {
		Logger.start(true,"不输入promotionId失败");
		try {
			CreatePromotionBean createpromotionBean = Shop2cnSellerPromotionCallService.initCreatePromotionBean(mchId, 1);
			Integer promotionId = Shop2cnSellerPromotionCallService.CreatepromotionCall(createpromotionBean);
			Shop2cnSellerPromotionCallService.PromotionEnd(mchId, promotionId);
//			promotiondeleteBean.setPromotionId(promotionId);
			promotiondeleteBean.setSellerId(mchId);
			promotiondeleteCall.setData(promotiondeleteBean);
			promotiondeleteCall.callService();			
			Logger.verifyEquals("400", promotiondeleteCall.getString("code"), "验证返回");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P3.class})
	@TestCase
	public void Tc_PromotionDelete_004() {
		Logger.start(true,"输入sellerid-promotionId不匹配失败");
		try {
			CreatePromotionBean createpromotionBean = Shop2cnSellerPromotionCallService.initCreatePromotionBean(mchId, 1);
			Integer promotionId = Shop2cnSellerPromotionCallService.CreatepromotionCall(createpromotionBean);
			Shop2cnSellerPromotionCallService.PromotionEnd(mchId, promotionId);
			promotiondeleteBean.setPromotionId(promotionId);
			promotiondeleteBean.setSellerId(1);
			promotiondeleteCall.setData(promotiondeleteBean);
			promotiondeleteCall.callService();			
			Logger.verifyEquals("300", promotiondeleteCall.getString("code"), "验证返回");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_PromotionDelete_005() {
		Logger.start(true,"未结束删除满减失败");
		try {
			CreatePromotionBean createpromotionBean = Shop2cnSellerPromotionCallService.initCreatePromotionBean(mchId, 1);
			Integer promotionId = Shop2cnSellerPromotionCallService.CreatepromotionCall(createpromotionBean);
//			Shop2cnSellerPromotionCallService.PromotionEnd(mchId, promotionId);
			promotiondeleteBean.setPromotionId(promotionId);
			promotiondeleteBean.setSellerId(mchId);
			promotiondeleteCall.setData(promotiondeleteBean);
			promotiondeleteCall.callService();			
			Logger.verifyEquals("300", promotiondeleteCall.getString("code"), "验证返回");
			Map m = Shop2cnSellerPromotionInfoWapper.getPromotionById(promotionId);
			Logger.debug(m);
			Logger.verifyEquals(false, m.get("isdel"), "验证isdel");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_PromotionDelete_006() {
		Logger.start(true,"重复删除满减-数据库结果正确");
		try {
			CreatePromotionBean createpromotionBean = Shop2cnSellerPromotionCallService.initCreatePromotionBean(mchId, 1);
			Integer promotionId = Shop2cnSellerPromotionCallService.CreatepromotionCall(createpromotionBean);
			Shop2cnSellerPromotionCallService.PromotionEnd(mchId, promotionId);
			promotiondeleteBean.setPromotionId(promotionId);
			promotiondeleteBean.setSellerId(mchId);
			promotiondeleteCall.setData(promotiondeleteBean);
			promotiondeleteCall.callService();			
			Thread.sleep(500);
			promotiondeleteCall.callService();		
			//重复调用{"code":300,"message":"促销活动不存在","data":null}
			Logger.verifyEquals("300", promotiondeleteCall.getString("code"), "验证返回");
			Map m = Shop2cnSellerPromotionInfoWapper.getPromotionById(promotionId);
			Logger.debug(m);
			Logger.verifyEquals(true, m.get("isdel"), "验证isdel");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_PromotionDelete_007() {
		Logger.start(true,"未开始已结束删除满减成功(场景:end在begin之前)");
		try {
			CreatePromotionBean createpromotionBean = Shop2cnSellerPromotionCallService.initCreatePromotionBean(mchId, 1);
			createpromotionBean.setBegin(YMTDateUtil.getBeforeOrNextDay(1,"yyyy-MM-dd HH:mm:ss"));
			createpromotionBean.setEnd(YMTDateUtil.getBeforeOrNextDay(2,"yyyy-MM-dd HH:mm:ss"));
			Integer promotionId = Shop2cnSellerPromotionCallService.CreatepromotionCall(createpromotionBean);
			Shop2cnSellerPromotionCallService.PromotionEnd(mchId, promotionId);
			promotiondeleteBean.setPromotionId(promotionId);
			promotiondeleteBean.setSellerId(mchId);
			promotiondeleteCall.setData(promotiondeleteBean);
			promotiondeleteCall.callService();			
			Logger.verifyEquals("200", promotiondeleteCall.getString("code"), "验证返回");
			Map m = Shop2cnSellerPromotionInfoWapper.getPromotionById(promotionId);
			Logger.debug(m);
			Logger.verifyEquals(true, m.get("isdel"), "验证isdel");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}